class DatafileController < ApplicationController
  def make_property_analysis_file
    #for each property id add property code tab analysis group code tab analysis group type code new line to content file
    string=String.new
    #For Division (DIV) /Business Unit
    Bid.find(:all).each { |bid| string << bid.prop_ref.to_s+"\t"+"DIV"+"\t"+bid.business_unit+"\n"  }
    #For Property Dept Contact (WHO)
    Bid.find(:all).each { |bid| string << bid.prop_ref.to_s+"\t"+"WHO"+"\t"+bid.prop_dept_contact+"\n"  }
    #For Project Type (TYP)
    Bid.find(:all).each { |bid| string << bid.prop_ref.to_s+"\t"+"TYP"+"\t"+bid.project_type+"\n"  }
    #For Business Case (BUS)
    Bid.find(:all).each { |bid| string << bid.prop_ref.to_s+"\t"+"BUS"+"\t"+bid.business_case+"\n"  }
    #For Year (YOC)
    Bid.find(:all).each { |bid| string << bid.prop_ref.to_s+"\t"+"YOC"+"\t"+bid.year.to_s+"\n"  }
    #For On_target *(OTG) Needs to be set up on Propman
    Bid.find(:all).each { |bid| string << bid.prop_ref.to_s+"\t"+"OTG"+"\t"+bid.on_target+"\n"  }
    #For Cashflow (YOQ)
    Bid.find(:all).each { |bid| string << bid.prop_ref.to_s+"\t"+"YOQ"+"\t"+bid.cashflow_qtr+"\n"  }
    #For Completed * (CMT)Needs to be set up on Propman
    Bid.find(:all).each { |bid| string << bid.prop_ref.to_s+"\t"+"CMT"+"\t"+bid.completed+"\n"  }
    
    File.open("C:/Prop_analysis.txt", "w")  { |f| f.write(string) }
    
    @pa_content = string 
    @pa_content_type='text/plain'
    @response.headers["Content-Type"] = @pa_content_type
    render :layout=>false
      
    
  end
  
  def make_key_note_file
  string=String.new
  #for RM2005 keynote is property id tab1 key-word tab2 tab3 tab4 tab5 tab6 tab7 tab8 tab9 cap_receipt.to_s tab10 cap_spend.to_s tab11 tab12 cap_retail_spend.to_s tab13 new_line
  Bid.find(:all).each { |bid| string << bid.prop_ref.to_s+"\t"+"RM2005"+"\t\t\t\t\t\t\t\t"+bid.cap_receipt.to_s+"\t"+bid.cap_spend.to_s+"\t\t"+bid.cap_retail_spend.to_s+"\t"+"\n"  }
  #for Top20 keynote is property id tab1 key-word tab2 tab3 tab4 tab5 tab6 tab7 tab8 tab9 tab10 tab11 tab12 tab13 comments new-line
  Bid.find(:all).each { |bid| string << bid.prop_ref.to_s+"\t"+"Top20"+"\t\t\t\t\t\t\t\t\t\t\t\t"+bid.comments+"\n"  }
  
  File.open("C:/Key_Note.txt", "w")  { |f| f.write(string) }
  
  @kn_content = string 
  @kn_content_type='text/plain'
  @response.headers["Content-Type"] = @kn_content_type
  render :layout=>false
  
  end
  
  
  
end
